<template>
	<view class="background1" v-show="show">
		<view class="flexcenter1" v-if="!list.data.length">
			<view class="placeholderimg" style="margin-top: 300rpx;">
				<image src="../../static/images/bg-icons/placeholderimg.png" mode=""></image>
			</view>
			<view class="zanwushuju">暂无数据~</view>
		</view>
		<view class="mainpadding padding-b">
			<view class="dizhilist ffffff" style="margin-top: 0rpx;"  @click="checkaddress(item)" v-for="item in list.data"
				:key="item.id" >
				<view class="flexleft  hangyi">
					<view style="margin-right: 20rpx;">{{item.name}}</view>
					<view>{{item.mobile}}</view>
				</view>
				<view class="hanger">
					<view style="margin-right: 20rpx;">
						<image class="place" src="../../static/images/hotel/dingwei.png"></image>
					</view>
					<view class="plactxt">{{item.cityinfo}}{{item.address_detail}}</view>
				</view>
				<view class="hangsan flexbetween">
					<view class="left flexleft" @click.stop="changeIndex(item)">
						<view class="yigouxuan margin_right" v-if="item.status==1"></view>
						<!-- 未勾选 -->
						<view class="weigouxuan margin_right" v-if="item.status==0"></view>
						<view>设为默认</view>
					</view>
					<view class="right flexleft" @click.stop="updatedizhi(item)">
						<view class="flexleft" style="margin-right: 61rpx;" >
							<image src="../../static/images/shopping/xiugai.png"
								style="width: 28rpx;height: 30rpx; margin-right: 15rpx;"></image>
							<view>编辑</view>
						</view>
						<view class="flexleft" @click.stop="deladress(item)">
							<image src="../../static/images/shopping/trash.png"
								style="width: 28rpx;height: 30rpx; margin-right: 15rpx;"></image>
							<view>删除</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="btn">
			<view class="btn-container" @click="goadddizhi" style="background-color: rgba(12, 224, 239, 1);">+新增收货地址
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				activeIndex: 1,
				list: {
					data: []
				},
				type:1,
				show:false,
			};
		},
		onLoad(options) {
			this.type = options.type
		},
		methods: {
			//设置默认
			changeIndex(item) {
				httpRequest.request('api/user/setAddressMr', 'GET', {
					id: item.id,
					status: item.status == 0 ? item.status = 1 : item.status = 0
				}, false, false, false).then(res => {
					if (res.code == 1) {
						httpRequest.toast('设置成功')
						this.init()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			//添加地址
			goadddizhi() {
				uni.navigateTo({
					url: '/pages/shopping/addshoudizhi'
				})
			},
			//删除地址
			deladress(item) {
				console.log(item)
				let _this = this
				httpRequest.modal('提示', '确认删除订单', true, (res) => {
					if (res) {
						httpRequest.request('api/user/deladdress', 'GET', {
							id: item.id,
						}, false, false, true).then(res => {
							httpRequest.toast(res.msg)
							_this.init()
							if (res.code == 1) {
								setTimeout(() => {
									uni.navigateBack(1)
								}, 1000)
							}
						}).catch(err => {
							httpRequest.toast(err.msg);
						})
					}
				})
			},
			checkaddress(item){
				uni.$emit("changeaddress",item.id)
				uni.navigateBack(1)
				return false
			},
			//修改地址
			updatedizhi(item) {
				uni.navigateTo({
					url: '/pages/shopping/addshoudizhi?id=' + item.id
				})
			},
			init() {
				let _this = this;
				httpRequest.request('api/user/addressList', 'GET', {
					
				}, false, false, false).then(res => {
					this.show=true
					if (res.code == 1) {
						_this.list.data = res.data
					}
				}).catch(err => {
					this.show=true
					httpRequest.toast(err.msg);
				})
			},
		},
		onShow() {
			this.init()
		},
		onReachBottom() {},

	}
</script>

<style lang="scss">
	.padding-b{
		padding-bottom: 150rpx !important;
	}
	.background1 {
		background-color: #fafafa;
		min-height: 100vh;
	}
.dizhilist{
	padding: 30rpx;
	margin-top: 30rpx;
}
.hangyi{
	font-size: 30rpx;
	font-family: PingFang SC-Heavy, PingFang SC;
	font-weight: 800;
	color: #000000;
	line-height: 35rpx;
}
.hanger{
	margin-top: 20rpx;
	display: flex;
	padding-bottom: 20rpx;
	border-bottom:solid 2rpx rgba(241, 241, 241, 1) ;
}
.place{
	width: 25rpx;
	height: 31rpx;
	flex: 1;
}
.plactxt{
	font-size: 26rpx;
	font-family: PingFang SC-Medium, PingFang SC;
	font-weight: 500;
	color: #333333;
	line-height: 30rpx;
	white-space: nowrap;
}
.hangsan{
	margin-top: 30rpx;
	font-size: 24rpx;
	font-family: PingFang SC-Medium, PingFang SC;
	font-weight: 500;
	color: #333333;
	line-height: 28rpx;
}
.weigouxuan {
		width: 40rpx;
		height: 40rpx;
		}

	.dizhilist {
		padding: 30rpx;
		margin-top: 30rpx;
	}

	.hangyi {
		font-size: 30rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
		line-height: 35rpx;
	}

	.hanger {
		margin-top: 20rpx;
		display: flex;
		padding-bottom: 20rpx;
		border-bottom: solid 2rpx rgba(241, 241, 241, 1);
	}

	.place {
		width: 25rpx;
		height: 31rpx;
	}

	.plactxt {
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 30rpx;
		white-space: nowrap;
	}

	.hangsan {
		margin-top: 30rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 28rpx;
	}

	.weigouxuan {
		width: 28rpx;
		height: 28rpx;
		background-size: 100% 100%;
		margin-right: 15rpx;

		background-image: url('@/static/images/hotel/unchecked.png');
	}

	.yigouxuan {
		width: 28rpx;
		height: 28rpx;
		margin-right: 15rpx;
		background-size: 100% 100%;
		background-image: url('@/static/images/hotel/checked.png');
	}
</style>
